package cn.jfinalbbs.hnair;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;



/**
 * 通过腾讯的ip分享计划，爬取网页
 * @author Administrator
 *
 */
public class HttpForIp
{
	private static DefaultHttpClient client = new DefaultHttpClient();
	public static void main(String[] args)
	{
		String entity = null;
		HttpGet getMethod = new HttpGet("http://114.251.242.135:8080/gxotarest/api/search-low-fare-trips.json");
		
		HttpResponse response = null;
		String OTACode = "GXAIRLINES_120";
		String ip = "220.249.72.237";
		String key = "69CDDG7D0042E4C672F46F0BACGAE3H2";
		try
		{
			
			
			response = client.execute(getMethod);
			entity = EntityUtils.toString(response.getEntity(),"GBK");
//			entity = ((entity.replace("\\n", "")).replace("\\/", "/")).replace(
//					"\\\"", "\"");
			System.out.println(entity);
			
//			if(entity.indexOf("<!--首页未登陆查询-->") > -1){
//				int begin = entity.indexOf("<p>该IP所在地为");
//				int end = entity.lastIndexOf("<div id=\"change_hint\" style=\"display:block\">");
//				if (begin >= 0 && begin < end) {
//					entity = entity.substring(begin, end);
//					
//				}
//				if (!"".equals(entity)
//						&& entity.indexOf("<span>") > 0) {
//					String bbsItems[] = entity.split("<span>");
//						String midtemp = bbsItems[1];
//						String[] splitTemp = midtemp.split("</span>");
//						String[] requireWord = splitTemp[0].split("&nbsp;");
//						for (int i = 0; i < requireWord.length; i++)
//						{
//							System.out.println(requireWord[i]);
//						}
//				}
//			}
		} catch (ClientProtocolException e)
		{
			e.printStackTrace();
		} catch (IOException e)
		{
			e.printStackTrace();
		} catch (ParseException e)
		{
			e.printStackTrace();
		}
	}

}
